﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using System.Security.Principal;
using Universum.Infrastructure.Persistence;
using TBlog = Universum.Model.Domain.Blogs.Blog;
using Universum.Model.Services.Blog;
using Universum.Controllers;
using System.Web.Mvc;
using Universum.Views.Blogs;
namespace Universum.Unit.Tests.Controllers
{
	[TestClass]
	public class When_requesting_blog_for_the_first_time
		:with_the_user_logged_in_and_no_blog_registered
	{
		public When_requesting_blog_for_the_first_time()
		{

		}
		[TestInitialize]
		public void re_establish_context()
		{
			base.EstablishContext();
		}
		const string owner = "mihai";
		
		[TestMethod]
		public void should_create_a_new_blog_for_the_user()
		{
			// Arrange
			const string owner = "mihai";

			
			RepositoryMock.Setup(r => r.SaveOrUpdate(
				It.Is<TBlog>( b=> b.Owner == owner)
				)).Verifiable();
			var blogService = new BlogServiceImpl(RepositoryMock.Object);
			
			// Act
			var controller = new BlogsController(blogService,
//				Repository,
				Principal
			);

			var viewResult = (RedirectToRouteResult)controller.Create();
			// Assert
			viewResult.should_not_be_null();
			viewResult.RouteValues["controller"].should_be_equal_to("Blogs");
			viewResult.RouteValues["action"].should_be_equal_to("Edit");
			PrincipalMock.VerifyAll();
			RepositoryMock.VerifyAll();

		}
		
	}
}
